What is cli-spinner?
The cli-spinner npm package is a simple and customizable spinner for command-line interfaces. It helps to indicate that a process is ongoing, providing a visual cue to users that something is happening in the background.
What are cli-spinner's main functionalities?
Basic Spinner
This feature allows you to create a basic spinner that shows a rotating animation in the terminal. The spinner can be customized with different characters.
const Spinner = require('cli-spinner').Spinner;
const spinner = new Spinner('processing.. %s');
spinner.setSpinnerString('|/-\\');
spinner.start();
setTimeout(() => spinner.stop(true), 5000);
Custom Spinner Strings
This feature allows you to use predefined spinner strings by passing an index to the setSpinnerString method. Each index corresponds to a different spinner animation.
const Spinner = require('cli-spinner').Spinner;
const spinner = new Spinner('loading.. %s');
spinner.setSpinnerString(18);
spinner.start();
setTimeout(() => spinner.stop(true), 5000);
Spinner with Custom Interval
This feature allows you to set a custom delay interval for the spinner animation, making it faster or slower depending on your needs.
const Spinner = require('cli-spinner').Spinner;
const spinner = new Spinner('waiting.. %s');
spinner.setSpinnerString('|/-\\');
spinner.setSpinnerDelay(100);
spinner.start();
setTimeout(() => spinner.stop(true), 5000);
Other packages similar to cli-spinner
ora
Ora is a more feature-rich spinner for command-line interfaces. It offers more customization options, such as different spinner styles, colors, and text. Ora also supports promises, making it easier to integrate with asynchronous operations.
cli-spinners
Cli-spinners is a collection of various spinner animations for use in command-line interfaces. It provides a wide range of spinner styles that can be easily integrated into your CLI applications. Unlike cli-spinner, it focuses more on providing a variety of spinner animations rather than customization.
elegant-spinner
Elegant-spinner is a minimalistic spinner for command-line interfaces. It provides a simple API for creating spinners with a focus on elegance and simplicity. It is less customizable compared to cli-spinner but is very lightweight and easy to use.
node-spinner
A simple spinner for node cli.
Installation
This package is available on npm as cli-spinner
.
npm install cli-spinner
Example usage
var Spinner = require('cli-spinner').Spinner;
var spinner = new Spinner('processing.. %s');
spinner.setSpinnerString('|/-\\');
spinner.start();
APIs
var obj = new Spinner('processing.. %s')
var obj = new Spinner({
text: 'processing.. %s',
stream: process.stderr,
onTick: function(msg){
this.clearLine(this.stream);
this.stream.write(msg);
}
})
Create a new spinner object. The advanced options can be used in any combination, none of them are required.
obj.start()
Starts the spinner.
obj.stop(clean)
Stops the spinner. Accepts a Boolean parameter to clean the console.
obj.isSpinning()
Returns true/false depending on whether the spinner is currently spinning.
obj.setSpinnerString(spinnerString)
Sets the spinner string. Accepts either a String or an Integer index to reference the built-in spinners.
obj.setSpinnerDelay(spinnerDelay)
Sets the spinner animation speed.
obj.setSpinnerTitle(spinnerTitle)
Sets the spinner title. Use printf-style strings to position the spinner.
Spinner.setDefaultSpinnerString(spinnerString)
Sets the default spinner string for all newly created instances. Accepts either a String or an Integer index to reference the built-in spinners.
Spinner.setDefaultSpinnerDelay(spinnerDelay)
Sets the default spinner delay for all newly created instances.
Demo
To see a demonstration of the built-in spinners, point your console at the example
folder and run:
node spinner.js